/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CostFrame.java
 *
 * Created on Mar 25, 2011, 12:53:41 PM
 */

package gbbmgmt;

import java.util.*;
import org.jdesktop.application.Action;
import javax.swing.JOptionPane;

/**
 *
 * @author dchapman
 */
public class CostFrame extends javax.swing.JFrame {

    public ArrayList<String[]> Cost;

    /** Creates new form CostFrame */
    public CostFrame() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBoxCost = new javax.swing.JComboBox();
        jButtonCustFirst = new javax.swing.JButton();
        jButtonCustPrev = new javax.swing.JButton();
        jButtonCustNext = new javax.swing.JButton();
        jButtonCustLast = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldCostID = new javax.swing.JTextField();
        jButtonSubmit = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldCostDesc = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldHCost = new javax.swing.JTextField();
        jTextFieldQCost = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldSCost = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextFieldTTCost = new javax.swing.JTextField();
        jTextFieldTWCost = new javax.swing.JTextField();
        jTextFieldSFCost = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jButtonModifyRecord = new javax.swing.JButton();
        jButtonDeleteRecord = new javax.swing.JButton();
        jButtonExit = new javax.swing.JButton();
        jButtonNewRecord = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jComboBoxCost.setName("jComboBoxCost"); // NOI18N
        jComboBoxCost.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBoxCostPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getActionMap(CostFrame.class, this);
        jButtonCustFirst.setAction(actionMap.get("FirstRecord")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(gbbmgmt.GBBMGMTApp.class).getContext().getResourceMap(CostFrame.class);
        jButtonCustFirst.setText(resourceMap.getString("jButtonCustFirst.text")); // NOI18N
        jButtonCustFirst.setName("jButtonCustFirst"); // NOI18N

        jButtonCustPrev.setAction(actionMap.get("PrevRecord")); // NOI18N
        jButtonCustPrev.setText(resourceMap.getString("jButtonCustPrev.text")); // NOI18N
        jButtonCustPrev.setName("jButtonCustPrev"); // NOI18N

        jButtonCustNext.setAction(actionMap.get("NextRecord")); // NOI18N
        jButtonCustNext.setText(resourceMap.getString("jButtonCustNext.text")); // NOI18N
        jButtonCustNext.setName("jButtonCustNext"); // NOI18N

        jButtonCustLast.setAction(actionMap.get("LastRecord")); // NOI18N
        jButtonCustLast.setText(resourceMap.getString("jButtonCustLast.text")); // NOI18N
        jButtonCustLast.setName("jButtonCustLast"); // NOI18N

        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jTextFieldCostID.setEditable(false);
        jTextFieldCostID.setText(resourceMap.getString("jTextFieldCostID.text")); // NOI18N
        jTextFieldCostID.setName("jTextFieldCostID"); // NOI18N

        jButtonSubmit.setAction(actionMap.get("SubmitRecord")); // NOI18N
        jButtonSubmit.setText(resourceMap.getString("jButtonSubmit.text")); // NOI18N
        jButtonSubmit.setName("jButtonSubmit"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jTextFieldCostDesc.setText(resourceMap.getString("jTextFieldCostDesc.text")); // NOI18N
        jTextFieldCostDesc.setName("jTextFieldCostDesc"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jTextFieldHCost.setText(resourceMap.getString("jTextFieldHCost.text")); // NOI18N
        jTextFieldHCost.setName("jTextFieldHCost"); // NOI18N

        jTextFieldQCost.setName("jTextFieldQCost"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jTextFieldSCost.setName("jTextFieldSCost"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jTextFieldTTCost.setName("jTextFieldTTCost"); // NOI18N

        jTextFieldTWCost.setName("jTextFieldTWCost"); // NOI18N

        jTextFieldSFCost.setName("jTextFieldSFCost"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jSeparator2.setName("jSeparator2"); // NOI18N

        jButtonModifyRecord.setAction(actionMap.get("ModifyRecord")); // NOI18N
        jButtonModifyRecord.setText(resourceMap.getString("jButtonModifyRecord.text")); // NOI18N
        jButtonModifyRecord.setName("jButtonModifyRecord"); // NOI18N

        jButtonDeleteRecord.setAction(actionMap.get("DeleteRecord")); // NOI18N
        jButtonDeleteRecord.setText(resourceMap.getString("jButtonDeleteRecord.text")); // NOI18N
        jButtonDeleteRecord.setName("jButtonDeleteRecord"); // NOI18N

        jButtonExit.setAction(actionMap.get("ExitCost")); // NOI18N
        jButtonExit.setText(resourceMap.getString("jButtonExit.text")); // NOI18N
        jButtonExit.setName("jButtonExit"); // NOI18N

        jButtonNewRecord.setAction(actionMap.get("NewRecord")); // NOI18N
        jButtonNewRecord.setText(resourceMap.getString("jButtonNewRecord.text")); // NOI18N
        jButtonNewRecord.setName("jButtonNewRecord"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBoxCost, 0, 249, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustFirst)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustPrev)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustNext)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonCustLast)
                .addContainerGap())
            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldCostID, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 250, Short.MAX_VALUE)
                        .addComponent(jButtonSubmit))
                    .addComponent(jTextFieldCostDesc, javax.swing.GroupLayout.DEFAULT_SIZE, 392, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldHCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel4))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldTTCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel7)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldQCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel5))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jTextFieldTWCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel8)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldSFCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldSCost, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 473, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonModifyRecord)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonNewRecord)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonDeleteRecord)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 135, Short.MAX_VALUE)
                .addComponent(jButtonExit)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jButtonCustPrev)
                    .addComponent(jButtonCustFirst)
                    .addComponent(jButtonCustNext)
                    .addComponent(jButtonCustLast)
                    .addComponent(jComboBoxCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonSubmit)
                    .addComponent(jTextFieldCostID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jTextFieldCostDesc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextFieldHCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldQCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jTextFieldSCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldTTCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jTextFieldTWCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextFieldSFCost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButtonModifyRecord)
                    .addComponent(jButtonExit)
                    .addComponent(jButtonNewRecord)
                    .addComponent(jButtonDeleteRecord))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBoxCostPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBoxCostPopupMenuWillBecomeInvisible
        // TODO add your handling code here:
        String Itm = jComboBoxCost.getSelectedItem().toString();

        for(String s[] : Cost){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetCostData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
}//GEN-LAST:event_jComboBoxCostPopupMenuWillBecomeInvisible

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new CostFrame().setVisible(true);
            }
        });
    }

    public void LoadList(){
        DBA.openDBCon();
        Cost = DBA.RunSQLQuery("SELECT CostID,CostDesc FROM Cost");
        DBA.closeDBCon();

        for(String s[] : Cost){
            jComboBoxCost.addItem(s[1]);
        }

        FirstRecord();
    }

    public void SetData(){
        jTextFieldCostID.setText(Integer.toString(DBA.CostID));
        jTextFieldCostDesc.setText(DBA.CostDesc);
        jTextFieldHCost.setText(Float.toString(DBA.HCost));
        jTextFieldQCost.setText(Float.toString(DBA.QCost));
        jTextFieldSCost.setText(Float.toString(DBA.SCost));
        jTextFieldTTCost.setText(Float.toString(DBA.TTCost));
        jTextFieldTWCost.setText(Float.toString(DBA.TWCost));
        jTextFieldSFCost.setText(Float.toString(DBA.SFCost));

        jButtonSubmit.setVisible(false);
    }

    @Action
    public void FirstRecord() {
        jComboBoxCost.setSelectedIndex(0);

        String Itm = jComboBoxCost.getSelectedItem().toString();
        for(String s[] : Cost){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetCostData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void LastRecord() {
        jComboBoxCost.setSelectedIndex(jComboBoxCost.getItemCount()-1);

        String Itm = jComboBoxCost.getSelectedItem().toString();
        for(String s[] : Cost){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetCostData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void PrevRecord() {
        if(jComboBoxCost.getSelectedIndex()>=1){
            jComboBoxCost.setSelectedIndex(jComboBoxCost.getSelectedIndex()-1);
        }

        String Itm = jComboBoxCost.getSelectedItem().toString();
        for(String s[] : Cost){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetCostData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void NextRecord() {
        if(jComboBoxCost.getSelectedIndex() <= (jComboBoxCost.getItemCount()-2)){
            jComboBoxCost.setSelectedIndex(jComboBoxCost.getSelectedIndex()+1);
        }

        String Itm = jComboBoxCost.getSelectedItem().toString();
        for(String s[] : Cost){
            if (s[1].equals(Itm)) {
                DBA.openDBCon();
                DBA.GetCostData(s[0]);
                DBA.closeDBCon();
            }
        }

        SetData();
    }

    @Action
    public void ModifyRecord() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will modify cost data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            //User wants to update database, check for differences.
            DBA.openDBCon();

            String CostID = jTextFieldCostID.getText();

            String query = "UPDATE Cost SET CostDesc='" +
                    jTextFieldCostDesc.getText() + "',HCost='" +
                    jTextFieldHCost.getText() + "',QCost='" +
                    jTextFieldQCost.getText() + "', SCost='" +
                    jTextFieldSCost.getText() + "', TTCost='" +
                    jTextFieldTTCost.getText() + "', TWCost='" +
                    jTextFieldTWCost.getText() + "', SFCost='" +
                    jTextFieldSFCost.getText() + "' ";

            query += "WHERE CostID='" + CostID + "'";

            DBA.RunSQLUpdateQuery(query);

            DBA.GetCostData(CostID);

            DBA.closeDBCon();

            SetData();
        }
    }

    @Action
    public void NewRecord() {
        //Make all appropriate variables blank.
        jComboBoxCost.setVisible(false);
        jButtonCustFirst.setVisible(false);
        jButtonCustLast.setVisible(false);
        jButtonCustNext.setVisible(false);
        jButtonCustPrev.setVisible(false);
        jLabel1.setVisible(false);
        jTextFieldCostID.setVisible(false);
        jButtonModifyRecord.setVisible(false);
        jButtonNewRecord.setVisible(false);
        jButtonDeleteRecord.setVisible(false);

        jButtonSubmit.setVisible(true);

        //reset text on all fields.
        jTextFieldCostDesc.setText("");
        jTextFieldHCost.setText("");
        jTextFieldQCost.setText("");
        jTextFieldSCost.setText("");
        jTextFieldTTCost.setText("");
        jTextFieldTWCost.setText("");
        jTextFieldSFCost.setText("");
    }

    @Action
    public void DeleteRecord() {
        String query = "DELETE FROM Cost WHERE CostID = '"
                + jTextFieldCostID.getText() + "'";
        int response = JOptionPane.showConfirmDialog(null,
                "Do you want to delete this entry from the Database?",
                "Warning",JOptionPane.WARNING_MESSAGE);
        if (response == 0){
            DBA.openDBCon();
            DBA.RunSQLUpdateQuery(query);
            DBA.closeDBCon();
            jComboBoxCost.removeAllItems();
            LoadList();
            LastRecord();
        }
    }

    @Action
    public void SubmitRecord() {
        int response = JOptionPane.showConfirmDialog(null,
                "This will add new employee data, continue?",
                "Warning",JOptionPane.WARNING_MESSAGE);

        if (response == 0){
            String query = "'" +
                jTextFieldCostDesc.getText() + "','" +
                jTextFieldHCost.getText() + "','" +
                jTextFieldQCost.getText() + "','" +
                jTextFieldSCost.getText() + "','" +
                jTextFieldTTCost.getText() + "','" +
                jTextFieldTWCost.getText() + "','" +
                jTextFieldSFCost.getText() + "'";

            String fields = "CostDesc,HCost,QCost,SCost,TTCost,TWCost,SFCost";

            //Enter information into database.
            DBA.openDBCon();
            DBA.RunSQLInsertQuery("Cost",fields,query);
            DBA.closeDBCon();

            jComboBoxCost.setVisible(true);
            jButtonCustFirst.setVisible(true);
            jButtonCustLast.setVisible(true);
            jButtonCustNext.setVisible(true);
            jButtonCustPrev.setVisible(true);
            jLabel1.setVisible(true);
            jTextFieldCostID.setVisible(true);
            jButtonModifyRecord.setVisible(true);
            jButtonNewRecord.setVisible(true);
            jButtonDeleteRecord.setVisible(true);

            jButtonSubmit.setVisible(false);

            jComboBoxCost.removeAllItems();
            LoadList();
            LastRecord();
        }
    }

    @Action
    public void ExitCost() {
        dispose();
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonCustFirst;
    private javax.swing.JButton jButtonCustLast;
    private javax.swing.JButton jButtonCustNext;
    private javax.swing.JButton jButtonCustPrev;
    private javax.swing.JButton jButtonDeleteRecord;
    private javax.swing.JButton jButtonExit;
    private javax.swing.JButton jButtonModifyRecord;
    private javax.swing.JButton jButtonNewRecord;
    private javax.swing.JButton jButtonSubmit;
    private javax.swing.JComboBox jComboBoxCost;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTextField jTextFieldCostDesc;
    private javax.swing.JTextField jTextFieldCostID;
    private javax.swing.JTextField jTextFieldHCost;
    private javax.swing.JTextField jTextFieldQCost;
    private javax.swing.JTextField jTextFieldSCost;
    private javax.swing.JTextField jTextFieldSFCost;
    private javax.swing.JTextField jTextFieldTTCost;
    private javax.swing.JTextField jTextFieldTWCost;
    // End of variables declaration//GEN-END:variables

}
